package homework.Map;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Two {

    public static void main(String[] args) {
         Scanner scan = new Scanner(System.in);
        Map<Integer,String> map = new HashMap<Integer, String>();
        map.put(1, "Amy");
        map.put(2, "Joe");
        map.put(3, "Tom");
        map.put(4, "Susan");

        //1.遍历
        Set set = map.keySet();
        for (Object key : set) {
            System.out.println(key + ":" + map.get(key));
        }

        //2.向该map集合中插入一个编码为5姓名为控制台输入的人名的信息
        System.out.println("请输入要添加的名字：");
        map.put(5,scan.next());

        //3.移除该map中的编号为4的信息
        map.remove(4);

        //4.将map集合中编号为3的姓名信息修改为"Tommy"
        if (map.containsKey(3)){
            map.put(3,"Tommy");
        }

        //5.再次遍历经过上述操作后的集合，并将序号与对应人名打印。(注：第一次输出和第二次输出需用空行隔开)
        System.out.println("\n");
        Set set1 = map.keySet();
        for (Object key : set1) {
            System.out.println(key + ":" + map.get(key));
        }

    }
}
